package com.example.SpringCloudUpload.controller;


import com.example.SpringCloudUpload.entity.Chunk;
import com.example.SpringCloudUpload.service.BigFileService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Class Description
 *
 * @author hulilei
 * @version 1.0.0
 * @date 2021/10/21 9:18
 */
@RestController
@Slf4j
@CrossOrigin(origins = "*", maxAge = 3600)
//@RequestMapping("/bigFile")
public class BigFileController {
    @Autowired
    BigFileService bigFileService;

    /**
     * 处理文件上传POST请求
     * 将上传的文件存放到服务器内
     *
     * @param chunk 文件块
     * @param response 响应
     * @return 上传响应状态
     */
    @PostMapping("/upload")
    public String uploadPost(@ModelAttribute Chunk chunk, HttpServletResponse response) throws IOException {
        return bigFileService.fileUploadPost(chunk, response);
    }

    @GetMapping("/removeFile")
    public String removeFile(@RequestParam("filePath") String filePath) {
        return bigFileService.removeFile(filePath);
    }
}
